using UnityEngine;

public class MySlider : MonoBehaviour
{
	public interface ISliderController
	{
		void BeginSlide();

		void EndSlide();

		void UpdateSlide();
	}

	[Header("Status")]
	public float value;

	public static MySlider current;

	public static ISliderController sliderController;

	private RectTransform marker;

	private float halfWidth;

	private float positionX;

	private float size;

	private const float minValue = 0.5f;

	private const float maxValue = 1.5f;

	private const int amountOfSteps = 10;

	private const float valueDiffrence = 1f;

	private void Start()
	{
		RectTransform component = GetComponent<RectTransform>();
		marker = component.GetChild(0).GetComponent<RectTransform>();
		size = component.sizeDelta.x;
		halfWidth = size / 2f;
		positionX = component.position.x;
		value = 1f;
	}

	public void BeginDrag()
	{
		current = this;
		sliderController.BeginSlide();
	}

	public void Drag()
	{
		Vector3 mouseWorldPosition = Main.GetMouseWorldPosition();
		float num = Mathf.Round(Mathf.Clamp01((mouseWorldPosition.x - positionX + halfWidth) / size) * 10f) / 10f;
		float num2 = 0.5f + num * 1f;
		if (num2 != value)
		{
			value = num2;
			mouseWorldPosition.Set((num - 0.5f) * size, 0f, 0f);
			marker.localPosition = mouseWorldPosition;
			sliderController.UpdateSlide();
		}
	}

	public void RestoreValue()
	{
		current = this;
		float num = 1f;
		SetValue(num);
	}

	private void SetValue(float newValue)
	{
		value = newValue;
		marker.localPosition = new Vector3((newValue / 2f - 0.5f) * size, 0f, 0f);
		sliderController.BeginSlide();
		sliderController.UpdateSlide();
	}
}
